
#!/bin/bash


logfile="/home/ec2-user/apache-tomcat-7.0.62/logs/log.log"

if [ ! -f $logfile ];then

exit 2;

fi


lines_no1=`cat /home/ec2-user/updatelogbash/filelineno1.log|awk '{print $1}'`

if [ ! -n "$lines_no1" ];then

lines_no1=1

else

:

fi

lines_no2=`ls -al /home/ec2-user/apache-tomcat-7.0.62/logs/log.log|awk '{print $5}'`

lines_diff=`expr $lines_no2 - $lines_no1`      #加减法 这里需要 运算符两边留空格

if [ $lines_diff -lt 0 ];then
 let lines_diff = 0 - $lines_diff;
fi

sed -i "s/$lines_no1/$lines_no2/" /home/ec2-user/updatelogbash/filelineno1.log    #sed在使用双引号的情况下，可以直接替换变量

if [ $lines_diff != 0 ];then
content1=`tail -c $lines_diff /home/ec2-user/apache-tomcat-7.0.62/logs/log.log|grep -B 15 -i exception`
content2=`tail -c $lines_diff /home/ec2-user/apache-tomcat-7.0.62/logs/log.log|grep -A 15 -i exception`
echo $content1
echo $content2
fi



